<?php
//ob_start();
session_start();
require 'head.php';

//if($_SESSION['adminName']=="")  		header("location:start.php");


$_Tamplate_name=$_REQUEST['Tamplate_name'];
if(isset($_REQUEST['Tamplate_name']) && $_REQUEST['Tamplate_name'] != "")
{
	
}
if(isset($_REQUEST['SendedBy']) && $_REQUEST['SendedBy'] != "")
{
	$_SendedBy=$_REQUEST['SendedBy'];
}


if(isset($_POST['Submit']) && $_POST['Submit'] == "Submit")
{
	$select_from_table="SELECT * FROM ".EMAILTEMPLATE."  WHERE templateName='".$_Tamplate_name."'";
	$execute_of_select_from_table=mysql_query($select_from_table);
	if(mysql_num_rows($execute_of_select_from_table) > 0)
	{
		//echo "update EMAILTEMPLATE  set templateText='".addslashes($_POST['template_content'])."' where templateName='".$_Tamplate_name."'<br><br>";//die();
		mysql_query("update ".EMAILTEMPLATE."  set `langId`=".$_POST['SelectLang'].", templateText='".addslashes($_POST['template_content'])."', templateSubject='".$_POST['emailSubject']."' where  templateName='".$_Tamplate_name."'");
	}
	else
	{
		//echo "insert into  EMAILTEMPLATE  set templateText='".addslashes($_POST['template_content'])."', languageId=".$_Languages_name." ,templateName='".$_Tamplate_name."'<br><br>";//die();
		mysql_query("insert into  ".EMAILTEMPLATE."  set `langId`=".$_POST['SelectLang'].", templateText='".addslashes($_POST['template_content'])."', templateSubject='".$_POST['emailSubject']."',templateName='".$_Tamplate_name."'");
	}
	
}



?>
<script language="javascript">
/*function FormSubmitTemp(arg1)
{
	//document.FormEmail.submit();
	window.location="?Languages_name="+arg1;
}
function FormSubmitTempAgain(arg1,arg2)
{
	window.location="?Languages_name="+arg2+"&Tamplate_name="+arg1;
	//document.templatesForm.submit();
}*/
function FormSubmitTempAgain(arg1)
{
	window.location="?Tamplate_name="+arg1;
	//document.templatesForm.submit();
}

</script>
<script language="javascript">
function fieldCheck()
{
	/*if(document.getElementById("Languages_name").value == "")
	{
		alert("Please Select A Language To Post templates.");
		document.getElementById("Languages_name").focus();
		return false;
	}*/
	if(document.getElementById("Tamplate_name").value == "")
	{
		alert("Please Select A Templates Name To Post templates.");
		document.getElementById("Tamplate_name").focus();
		return false;		
	}
	/*if(document.getElementById("SendedBy").value == "")
	{
		alert("Please Select A Type Of Senders.");
		document.getElementById("SendedBy").focus();
		return false;		
	}*/
	if(document.getElementById("emailSubject").value == "")
	{
		alert("Please Type A Subject Of Templates.");
		document.getElementById("emailSubject").focus();
		return false;		
	}
	if(document.getElementById("template_content").value == "")
	{
		alert("Please Type The Content Of Templates.");
		document.getElementById("template_content").focus();
		return false;		
	}
	else
	{
		var myRegExp = /Sms/;
		//var string1 = "Today John went to the store and talked with Alex.";
		var string1 = document.getElementById("Tamplate_name").value;
		var matchPos1 = string1.search(myRegExp);
		if(matchPos1 != -1)
		{
			if(document.getElementById("template_content").value.length > 456)
			{
				alert("Your Content MustBe Between 0 To 456");
				document.getElementById("template_content").focus();
				return false;		
			}
		}
	}
	
}
</script>
<fieldset>
<legend class="LEGEND">Email Templates Management</legend>
  <table width="100%" border="0" cellspacing="0" cellpadding="5">
  <form name="FormEmail" id="FormEmail" method="post" action="" onsubmit="return fieldCheck();">
            <!--<tr>
            <td>
            &nbsp;Selete Language</td>
            <td><select name="Languages_name" id="Languages_name" onChange="FormSubmitTemp(this.value);">
          		<option value="">----select----</option>
            <?php
            if(mysql_num_rows($execute_query_of_select_LANGUAGES) > 0)
            {
            while($result_of_execute_query_of_select_LANGUAGES=mysql_fetch_assoc($execute_query_of_select_LANGUAGES))
            {
            if($result_of_execute_query_of_select_LANGUAGES['languageId'] == $_Languages_name)
            $_selected="selected";
            else
            $_selected="";
            ?>
            <option value="<?php echo $result_of_execute_query_of_select_LANGUAGES['languageId']; ?>" <?php echo $_selected; ?>><?php echo $result_of_execute_query_of_select_LANGUAGES['name']; ?></option>
            <?php
            }
            }
            ?>
            </select></td>
            </tr> -->
            <tr>
            <td>Select Template</td>
            <td><table width="100%" border="0" align="center" cellpadding="5" cellspacing="0">
		<TR><TD>
			<?php
			$select_TEMPLATE_NAME="SELECT templateName,templateId from ".EMAILTEMPLATE." ";		
			$execute_query_of_select_TEMPLATE_NAME=mysql_query($select_TEMPLATE_NAME);
			//echo $select_TEMPLATE_NAME.'<br>';
			?>
			<select name="Tamplate_name" id="Tamplate_name" onchange="FormSubmitTempAgain(this.value)">
          		<option value="">----Select Templates----</option>
            <?php
            
            if(mysql_num_rows($execute_query_of_select_TEMPLATE_NAME) >= 15)
            {
				while($result_of_execute_query_of_select_TEMPLATE_NAME=mysql_fetch_assoc($execute_query_of_select_TEMPLATE_NAME))
				{
				if($result_of_execute_query_of_select_TEMPLATE_NAME['templateName'] == $_Tamplate_name)
				$_selected_="selected";
				else
				$_selected_="";
				?>
				<option value="<?php echo $result_of_execute_query_of_select_TEMPLATE_NAME['templateName']; ?>" <?php echo $_selected_; ?>><?php echo $result_of_execute_query_of_select_TEMPLATE_NAME['templateName']; ?></option>
				<?php
				}
            }
			else
			{
            ?>
			<option value="Email Verification" <?php if($_Tamplate_name == "Email Verification") echo 'selected'; ?>>Email Verification</option>
			<option value="Successfull Registration" <?php if($_Tamplate_name == "Successfull Registration") echo 'selected'; ?>>Successfull Registration</option>
			<option value="Invite Reviewer" <?php if($_Tamplate_name == "Invite Reviewer") echo 'selected'; ?>>Invite Reviewer</option>
			<option value="Report Abuse" <?php if($_Tamplate_name == "Report Abuse") echo 'selected'; ?>>Report Abuse</option>
			<option value="Successfully Awarded" <?php if($_Tamplate_name == "Successfully Awarded") echo 'selected'; ?>>Successfully Awarded</option>
			<option value="Successfully Awarded Users" <?php if($_Tamplate_name == "Successfully Awarded Users") echo 'selected'; ?>>Successfully Awarded Users</option>
			<option value="Password Recovery" <?php if($_Tamplate_name == "Password Recovery") echo 'selected'; ?>>Password Recovery</option>
			<option value="Invite Contributor" <?php if($_Tamplate_name == "Invite Contributor") echo 'selected'; ?>>Invite Contributor</option>
			<option value="Invitation Email" <?php if($_Tamplate_name == "Invitation Email") echo 'selected'; ?>>Invitation Email</option>
			<option value="Email Alerts For Stock High" <?php if($_Tamplate_name == "Email Alerts For Stock High") echo 'selected'; ?>>Email Alerts For Stock High</option>
			<option value="Email Alerts For Stock Low" <?php if($_Tamplate_name == "Email Alerts For Stock Low") echo 'selected'; ?>>Email Alerts For Stock Low</option>
			<option value="Email Alerts For Max Loss" <?php if($_Tamplate_name == "Email Alerts For Max Loss") echo 'selected'; ?>>Email Alerts For Max Loss</option>
			<option value="Email Alerts For First Profit" <?php if($_Tamplate_name == "Email Alerts For First Profit") echo 'selected'; ?>>Email Alerts For First Profit</option>
			<option value="Email Alerts For Next Profit" <?php if($_Tamplate_name == "Email Alerts For Next Profit") echo 'selected'; ?>>Email Alerts For Next Profit</option>
			<option value="Email Alerts For Must Sell Point" <?php if($_Tamplate_name == "Email Alerts For Must Sell Point") echo 'selected'; ?>>Email Alerts For Must Sell Point</option>
		<!--	<option value="Get Earning From A Plan" <?php if($_Tamplate_name == "Get Earning From A Plan") echo 'selected'; ?>>Get Earning From A Plan</option>
			<option value="Deposit Funds To A Plan" <?php if($_Tamplate_name == "Deposit Funds To A Plan") echo 'selected'; ?>>Deposit Funds To A Plan</option>
			<option value="Withdrawal Request For A Member" <?php if($_Tamplate_name == "Withdrawal Request For A Member") echo 'selected'; ?>>Withdrawal Request For A Member</option>
			<option value="Accept Or Reject Friendship" <?php if($_Tamplate_name == "Accept Or Reject Friendship") echo 'selected'; ?>>Accept Or Reject Friendship</option>
			<option value="Change Password" <?php if($_Tamplate_name == "Change Password") echo 'selected'; ?>>Change Password</option>
			<option value="change password from settings" <?php if($_Tamplate_name == "change password from settings") echo 'selected'; ?>>change password from settings</option>
			<option value="Password Recovery" <?php if($_Tamplate_name == "Password Recovery") echo 'selected'; ?>>Password Recovery</option> -->
<!--************************************* MESSAGES FOR NON REGISTER MEMBERS STRATS HERE *************************************** -->	
			<!--<option>------------------------------------------------------</option>
			<option>Templates For Non-Register Members</option><option></option>
			<option value="Non Register First Day Message" <?php if($_Tamplate_name == "Non Register First Day Message") echo 'selected'; ?>>
			Non Register First Day Message</option>
			<option value="Non Register 4 Days Later Message" <?php if($_Tamplate_name == "Non Register 4 Days Later Message") echo 'selected'; ?>>
			Non Register 4 Days Later Message</option>
			<option value="Non Register 10 Days Later Message" <?php if($_Tamplate_name == "Non Register 10 Days Later Message") echo 'selected'; ?>>
			Non Register 10 Days Later Message</option>
			<option value="Non Register 14 Days Later Message" <?php if($_Tamplate_name == "Non Register 14 Days Later Message") echo 'selected'; ?>>
			Non Register 14 Days Later Message</option>
			<option value="Non Register 20 Days Later Message" <?php if($_Tamplate_name == "Non Register 20 Days Later Message") echo 'selected'; ?>>
			Non Register 20 Days Later Message</option>
			<option value="Non Register 30 Days Later Message" <?php if($_Tamplate_name == "Non Register 30 Days Later Message") echo 'selected'; ?>>
			Non Register 30 Days Later Message</option>
			<option value="Non Register 45 Days Later Message" <?php if($_Tamplate_name == "Non Register 45 Days Later Message") echo 'selected'; ?>>
			Non Register 45 Days Later Message</option> -->
			
<!--************************************* MESSAGES FOR NON REGISTER MEMBERS ENDS HERE *************************************** -->			
			
<!--************************************* MESSAGES FOR NON ACTIVE MEMBERS STRATS HERE *************************************** -->	

			<!--<option>----------------------------------------------------</option>
			<option>Templates For Non-Active Members</option><option></option>
		
			<option value="Non Active First Day Message" <?php if($_Tamplate_name == "Non Active First Day Message") echo 'selected'; ?>>
			Non Active First Day Message</option>
			<option value="Non Active 4 Days Later Message" <?php if($_Tamplate_name == "Non Active 4 Days Later Message") echo 'selected'; ?>>
			Non Active 4 Days Later Message</option>
			<option value="Non Active 10 Days Later Message" <?php if($_Tamplate_name == "Non Active 10 Days Later Message") echo 'selected'; ?>>
			Non Active 10 Days Later Message</option>
			<option value="Non Active 14 Days Later Message" <?php if($_Tamplate_name == "Non Active 14 Days Later Message") echo 'selected'; ?>>
			Non Active 14 Days Later Message</option>
			<option value="Non Active 20 Days Later Message" <?php if($_Tamplate_name == "Non Active 20 Days Later Message") echo 'selected'; ?>>
			Non Active 20 Days Later Message</option>
			<option value="Non Active 30 Days Later Message" <?php if($_Tamplate_name == "Non Active 30 Days Later Message") echo 'selected'; ?>>
			Non Active 30 Days Later Message</option>
			<option value="Non Active 45 Days Later Message" <?php if($_Tamplate_name == "Non Active 45 Days Later Message") echo 'selected'; ?>>
			Non Active 45 Days Later Message</option> -->
<!--************************************* MESSAGES FOR NON ACTIVE MEMBERS ENDS HERE *************************************** -->			
			
<!--************************************* MESSAGES FOR ACTIVE MEMBERS STRATS HERE *************************************** -->	
			<!--<option>------------------------------------------------</option>
			<option>Templates For Active Members</option><option></option>
			<option value="Active First Day Message" <?php if($_Tamplate_name == "Active First Day Message") echo 'selected'; ?>>
			Active First Day Message</option>
			<option value="Active 4 Days Later Message" <?php if($_Tamplate_name == "Active 4 Days Later Message") echo 'selected'; ?>>
			Active 4 Days Later Message</option>
			<option value="Active 10 Days Later Message" <?php if($_Tamplate_name == "Active 10 Days Later Message") echo 'selected'; ?>>
			Active 10 Days Later Message</option>
			<option value="Active 14 Days Later Message" <?php if($_Tamplate_name == "Active 14 Days Later Message") echo 'selected'; ?>>
			Active 14 Days Later Message</option>
			<option value="Active 20 Days Later Message" <?php if($_Tamplate_name == "Active 20 Days Later Message") echo 'selected'; ?>>
			Active 20 Days Later Message</option>
			<option value="Active 30 Days Later Message" <?php if($_Tamplate_name == "Active 30 Days Later Message") echo 'selected'; ?>>
			Active 30 Days Later Message</option>
			<option value="Active 45 Days Later Message" <?php if($_Tamplate_name == "Active 45 Days Later Message") echo 'selected'; ?>>
			Active 45 Days Later Message</option> -->
<!--************************************* MESSAGES FOR ACTIVE MEMBERS ENDS HERE *************************************** -->			

<!--************************************* MESSAGES FOR SMS REMAINDER STRATS HERE *************************************** -->	
			<!--<option>--------------------------------------------------</option>
			<option>Templates For Sms Reminder </option><option></option>
			<option value="Sms Reminder First Day Message" <?php if($_Tamplate_name == "Sms Reminder First Day Message") echo 'selected'; ?>>
			Sms Reminder First Day Message</option>
			<option value="Sms Reminder 4 Days Later Message" <?php if($_Tamplate_name == "Sms Reminder 4 Days Later Message") echo 'selected'; ?>>
			Sms Reminder 4 Days Later Message</option>
			<option value="Sms Reminder 10 Days Later Message" <?php if($_Tamplate_name == "Sms Reminder 10 Days Later Message") echo 'selected'; ?>>
			Sms Reminder 10 Days Later Message</option>
			<option value="Sms Reminder 14 Days Later Message" <?php if($_Tamplate_name == "Sms Reminder 14 Days Later Message") echo 'selected'; ?>>
			Sms Reminder 14 Days Later Message</option>
			<option value="Sms Reminder 20 Days Later Message" <?php if($_Tamplate_name == "Sms Reminder 20 Days Later Message") echo 'selected'; ?>>
			Sms Reminder 20 Days Later Message</option>
			<option value="Sms Reminder 30 Days Later Message" <?php if($_Tamplate_name == "Sms Reminder 30 Days Later Message") echo 'selected'; ?>>
			Sms Reminder 30 Days Later Message</option>
			<option value="Sms Reminder 45 Days Later Message" <?php if($_Tamplate_name == "Sms Reminder 45 Days Later Message") echo 'selected'; ?>>
			Sms Reminder 45 Days Later Message</option> -->
<!--************************************* MESSAGES FOR SMS REMAINDER ENDS HERE *************************************** -->			
			
			
			<?php
			}
			?>
            </select></TD>
	<td><strong><a href="javascript:void(0);" onClick="window.open('email_var_details.php', 'name', 'height=500, width=630, scrollbars=yes');" title="<?php echo "Click here to see all the variables used in the mail content"; ?>">Check Out Variables</a></strong></td>
		</TR></table></td>
            </tr>
            <!--<tr>
              <td valign="top">Select SendedBy </td>
              <td><label>
			<?php
			$select_SENDED_BY="select templateSendedBy,templateId from ".EMAILTEMPLATE."   where templateName='".$_Tamplate_name."'";		
			$execute_query_of_select_SENDED_BY=mysql_query($select_SENDED_BY);
			//echo $select_TEMPLATE_NAME.'<br>';
			?>
                <select name="SendedBy" id="SendedBy">
          		<option value="">----Select SendedBy----</option>
            <?php
            
            if(mysql_num_rows($execute_query_of_select_SENDED_BY) > 0 || mysql_num_rows($execute_query_of_select_SENDED_BY) != '')
            {
				$result_of_execute_query_of_select_SENDED_BY=mysql_fetch_assoc($execute_query_of_select_SENDED_BY)
				?>
				<option value="Cashgainers" <?php if($result_of_execute_query_of_select_SENDED_BY['templateSendedBy'] == 'Cashgainers') echo 'selected'; ?>>Cashgainers</option>
				<option value="Member Name" <?php if($result_of_execute_query_of_select_SENDED_BY['templateSendedBy'] == 'Member Name') echo 'selected'; ?>>Member Name</option>
				<option value="Member email" <?php if($result_of_execute_query_of_select_SENDED_BY['templateSendedBy'] == 'Member email') echo 'selected'; ?>>Member email</option>
				<?php
            }
			else
			{
            ?>
				<option value="Cashgainers">Cashgainers</option>
				<option value="Member Name">Member Name</option>
				<option value="Member email">Member email</option>
             
			 <?php
			 }
			 ?>   </select>
              </label></td>
            </tr> -->
			<tr>
				<td align="left">
					Select language :
				</td>
				
				<td align="left">
					<?php
						if(isset( $_Tamplate_name) &&  $_Tamplate_name!= '')
						{
							$select_LAng="select `langId` from ".EMAILTEMPLATE."  where templateName='".$_Tamplate_name."'";
							$EXEsellang=mysql_query($select_LAng) or die("Selection Error Language :<br>".$select_LAng.'<br>'.mysql_error());;
							if(mysql_num_rows($EXEsellang) > 0)
							{
								$selectedResuld=mysql_fetch_assoc($EXEsellang);
								$selectedLang=$selectedResuld['langId'];
							}
							else
							{
								$selectedLang='';
							}
						}
						$selectlanguage="SELECT * FROM ".LANGUAGE." WHERE 1";
						$Exequery=mysql_query($selectlanguage) or die("Selection Error Language :<br>".$selectlanguage.'<br>'.mysql_error());
						if(mysql_num_rows($Exequery) > 0)
						{
					?>
					<select name="SelectLang" id="SelectLang">
						<option value="" <?php if($selectedLang == '') echo 'selected';?>>--Select one--</option>
					<?php
							while($resultExequery = mysql_fetch_assoc($Exequery))
							{
								if($resultExequery['langId'] == $selectedLang)
									$selected="selected";
								else
									$selected="";
					?>
						<option value="<?php echo $resultExequery['langId']?>" <?php echo $selected;?>><?php echo $resultExequery['langName']?></option>
					<?php
							}
					?>
					</select>
					<?php
						}
					?>
					
				
				</td>
			</tr>
            <?php
            if(isset( $_Tamplate_name) &&  $_Tamplate_name!= '')
            {
				$select_TEMPLATE_TEXT="select templateText,templateSubject from ".EMAILTEMPLATE."  where templateName='".$_Tamplate_name."'";
				//echo $select_TEMPLATE_TEXT.'<br><br>';
				$execute_query_of_select_TEMPLATE_TEXT=mysql_query($select_TEMPLATE_TEXT)or die(mysql_error());
				if(mysql_num_rows($execute_query_of_select_TEMPLATE_TEXT) > 0)
				{
					$result_of_execute_query_of_select_TEMPLATE_TEXT=mysql_fetch_assoc($execute_query_of_select_TEMPLATE_TEXT);
					$templatetext=$result_of_execute_query_of_select_TEMPLATE_TEXT['templateText'];
					$emailSubject=$result_of_execute_query_of_select_TEMPLATE_TEXT['templateSubject'];
				}
				else
				{
					$templatetext='';
					$emailSubject='';
				}
            }
            else
            $templatetext='';
            ?>
            <tr>
              <td valign="top">Template Subject </td>
              <td><label>
                <input name="emailSubject" type="text" id="emailSubject" value="<?php echo $emailSubject; ?>" size="<?php if($emailSubject != '') echo (int)(strlen($emailSubject)+5); else echo '88'; ?>" />
              </label></td>
            </tr>
            <tr>
            <td valign="top">Template Content</td>
            <td><label>
            <textarea name="template_content" id="template_content" cols="85" rows="10"><?php echo $templatetext; ?></textarea>
            </label></td>
            </tr>
            <tr>
            <td>&nbsp;</td>
            <td><label>
            <input type="submit" name="Submit" id="Submit" value="Submit">
            </label></td>
            </tr>
            <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            </tr>
    </form>
  </table>
  
  
<?php
if(isset($_POST['Update']) && $_POST['Update']!='')
{
	$last_id=$_POST['last_id'];
	$first_id=$_POST['first_id'];
	for($i=$first_id; $i<=$last_id;$i++)
	{
		if(isset($_POST['d'.$i]))
		{
			mysql_query("DELETE FROM ".EMAILTEMPLATE." WHERE templateId=".$i)or die(mysql_error());
		}
	}
	echo '<script>window.location="emailtemplates.php"</script>';
	
}
?>  

  <form name="form1" method="post" action="">
    <table width="100%" border="0" cellspacing="0" cellpadding="5" class="tabbod">
      <?php
	  $SELECTlanguage="SELECT * FROM ".LANGUAGE." WHERE 1";
	  $exeselang=mysql_query($SELECTlanguage) or die("Error in selection: <br>".$SELECTlanguage.'<br>'.mysql_error());
	  if(mysql_num_rows($exeselang) > 0)
	  {
	  	$CheckAvailavility=0;
	  	while($resultexeselang=mysql_fetch_assoc($exeselang))
		{
	?>
			<tr bgcolor="#C1D2EC">
			    <td height="32" align="left" valign="middle" colspan="3" style="font-size:14px; font-weight:bold;"><?php echo ucfirst($resultexeselang['langName']); ?>&nbsp;Email Templates</td>
			    <td align="left" valign="middle">&nbsp;</td>
			    <td align="left" valign="middle">&nbsp;</td>
			</tr>
		      <tr bgcolor="#6F8DBC">
		        <td width="7%" height="28" align="left" valign="middle"><font color="#FFFFFF"><strong>Id</strong></font></td>
		        <td colspan="2" align="left" valign="middle"><font color="#FFFFFF"><strong>TemplateName</strong></font></td>
		        <!--<td width="27%" align="left"><font color="#FFFFFF"><strong>Language</strong></font></td> -->
		        <td width="31%" align="left" valign="middle"><font color="#FFFFFF"><strong>Edit</strong></font></td>
		        <td width="22%" align="left" valign="middle"><font color="#FFFFFF"><strong>Delete</strong></font></td>
		      </tr>
	
	<?php
			$select__From__Table="SELECT * FROM ".EMAILTEMPLATE." WHERE `langId`=".$resultexeselang['langId']." order by templateId asc";
		  //echo $select__From__Table.'<br><br>';
		  $execute_select__From__Table=mysql_query($select__From__Table);
		  if(mysql_num_rows($execute_select__From__Table) > 0)
		  {
		  	//$counter__=1;
			$CheckAvailavility=1;
			$loop=0;
		  	while($result_of_execute_select__From__Table=mysql_fetch_assoc($execute_select__From__Table))
			{
				$loop++;
				if($loop%2 == 0) $bgcolor = "#F0F0FF";
				else $bgcolor = "#CCCCFF";
		  ?>
		  <tr bgcolor="<?php echo $bgcolor; ?>">
		    <td height="32" align="left" valign="middle"><?php echo $loop; ?></td>
		    <td align="left" valign="middle" colspan="2"><?php echo $result_of_execute_select__From__Table['templateName']; ?></td>
		    <!--<td align="left" valign="top"><?php echo $result_of_execute_select__From__Table['name']; ?></td> -->
		    <td align="left" valign="middle"><a href="emailtemplates.php?Tamplate_name=<?php echo $result_of_execute_select__From__Table['templateName']; ?>">Edit</a></td>
		    <td align="left" valign="middle"><label>
		    <input type="checkbox" name="d<?php echo $result_of_execute_select__From__Table['templateId']; ?>" id="d<?php echo $result_of_execute_select__From__Table['templateId']; ?>">
		    </label></td>
		  </tr>
		  <?php
		  		/*if($counter__ == 1)
				{
					$first_id=$result_of_execute_select__From__Table['templateId'];
					$last_id=$result_of_execute_select__From__Table['templateId'];
				}
				else
				{				
					$last_id=$result_of_execute_select__From__Table['templateId'];
				}
		  		$counter__++;*/
		  	}
			  $select_maxId_MinId="select max(templateId) as MAx_iD, min(templateId) as MIn_iD from ".EMAILTEMPLATE;
			  //echo $select_maxId_MinId.'<br><br>';
			  $execute_of_select_maxId_MinId=mysql_query($select_maxId_MinId)or die(mysql_error());
			  if(mysql_num_rows($execute_of_select_maxId_MinId) > 0)
			  {
					$result_of_execute_of_select_maxId_MinId=mysql_fetch_assoc($execute_of_select_maxId_MinId);
					$first_id=$result_of_execute_of_select_maxId_MinId['MIn_iD'];
					$last_id=$result_of_execute_of_select_maxId_MinId['MAx_iD'];
			  }
			 ?>
		 <?php
		  }
		  else
		  {
		  ?>
		  <tr>
		    <td>&nbsp;</td>
		    <td height="96" colspan="3" align="center" valign="middle" class="DISPLAYMESSAGES">No Templates Available For <?php echo ucfirst($resultexeselang['langName']);?>! </td>
		    <td>&nbsp;</td>
		  </tr>
		  <?php
		  }
	?>
		  <tr>
		    <td>&nbsp;</td>
		    <td width="11%">&nbsp;</td>
		    <td width="29%">&nbsp;</td>
		    <td>&nbsp;</td>
		    <td>&nbsp;</td>
		  </tr>
	
	<?php
		  
		}
		if($CheckAvailavility !=  0)
		{
	?>
		  <tr>
		    <td>&nbsp;</td>
		    <td width="11%">&nbsp;</td>
		    <td width="29%">&nbsp;</td>
		    <td>&nbsp;</td>
		    <td><input type="hidden" name="first_id" id="first_id" value="<?php echo $first_id; ?>">
		      <input type="hidden" name="last_id" id="last_id" value="<?php echo $last_id; ?>">
		      <input type="submit" name="Update" id="Update" value="Update Records"></td>
		  </tr>
	
	<?php
		}
	  }
	  else
	  {
	  ?>
		<tr>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td height="96" colspan="2" valign="middle" class="DISPLAYMESSAGES">No Templates Available! </td>
			<td>&nbsp;</td>
		</tr>
	  <?php
	  }
	  ?>
    </table>
</form>
</fieldset>
<?php
include_once("foot.php");
?>
